#ifndef _CTHREAD_THREAD_H_
#define _CTHREAD_THREAD_H_

#include "runnable.h"
#include <pthread.h>

namespace CThread
{

class Thread 
{	
public:	
	Thread(Runnable* pRunnable=NULL);
	virtual ~Thread();

	virtual void run()
	{
		if ( m_pRunnable != NULL )
			m_pRunnable->run();
	}
  /**
   * Starts the thread. Does platform specific thread creation and
   * configuration then invokes the run method of the Runnable object bound
   * to this thread.
   */
	void start();

  /**
   * Join this thread. Current thread blocks until this target thread
   * completes.
   */
	void join();

  /**
   * Gets the thread's platform-specific ID
   */
	pthread_t getId(){return m_tid;}

  /**
   * Gets the runnable object this thread is hosting
   */
	Runnable* getRunnable() const { return m_pRunnable; }

	void setRunnable(Runnable* pRunnable) { m_pRunnable = pRunnable; }

private:	
	static void* threadMain(void* arg);

protected:
	Runnable* m_pRunnable;
	pthread_t m_tid;
};

};

#endif 

